package singleton;

import java.util.Random;

public class Multiton {
    private Multiton(){}
    //默认三个实例
    private static int i = 3;
    private static Multiton[] array = new Multiton[i];
    public static Multiton getInstance(){
        Random r = new Random();
        int quantity = r.nextInt(i);
        if(array[quantity] == null){
            array[quantity] = new Multiton();
        }
        return array[quantity];
    }
    //开放控制实例数量，数量必须大于1
    public static boolean quantity(int quantity){
        if(quantity < 1){
            return false;
        }
        i = quantity;
        return true;
    }
}
